package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.ChatRoom;
import com.example.demo.service.ChatRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chatroom/")
public class ChatRoomController {
    @Autowired
    private ChatRoomService chatRoomService;

    @GetMapping
    public Result getAllChatRooms() {
        List<ChatRoom> chatRooms = chatRoomService.getAllChatRooms();
        return Result.success(chatRooms);
    }

    @PostMapping
    public Result createChatRoom(@RequestBody ChatRoom chatRoom) {
        chatRoomService.createChatRoom(chatRoom);
        return Result.success(chatRoom);
    }

    @GetMapping("/detail/{id}/")
    public Result getChatRoomById(@PathVariable long id) {
        ChatRoom chatRoom = chatRoomService.getChatRoomById(id);
        return Result.success(chatRoom);
    }
}